<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<html>
<head>
<title>仓库</title>
<meta name="decorator" content="default" />
<link rel="stylesheet" type="text/css"
	href="${ctxStatic}/easyui/themes/default/easyui.css">
<link rel="stylesheet" type="text/css"
	href="${ctxStatic}/easyui/themes/icon.css">
<link rel="stylesheet" type="text/css"
	href="${ctxStatic}/easyui/demo/demo.css">
<link rel="stylesheet" type="text/css"
	href="${ctxStatic}/font-awesome-4.7.0/css/font-awesome.min.css">
<script type="text/javascript" src="${ctxStatic}/easyui/jquery.min.js"></script>
<script type="text/javascript"
	src="${ctxStatic}/easyui/jquery.easyui.min.js"></script>
</head>
<body>
	<table id="dg" title="仓库-物料详细" style="height:auto" class="easyui-datagrid"
			data-options="rownumbers:true,singleSelect:true,pagination:true,
				method:'get'">
		<thead>
			<tr>
				<th data-options="field:'cInvCode',width:100">物料编号</th>
				<th data-options="field:'cInvName',width:500">物料名称</th>
				<th data-options="field:'cInvAmount',width:50">剩余数</th>
			</tr>
		</thead>
	</table>
	
	<div id="dlg" class="easyui-dialog"  style="width:400px;height:200px;padding:10px">
			<span>仓库名称：</span><input id="repository"  class='easyui-textbox'  style='width:30%;height:22px'/>
	</div>
	
	
	<script type="text/javascript">
		function Query() {
	        var url = "${ctx}/erp/warehouse/repositoryPage?page=1&pageSize=10&repository="+repository;
	        console.log(url);
	        $('#dg').datagrid('options').url = url; //设置表格数据的来源URL
	        $('#dg').datagrid({onLoadSuccess : function(data){
	        }});
	        $('#dg').datagrid('reload'); //重新加载表格
	    } 
	    var repository='';
		$(function(){
			repository='${repository}';
			if('0'!=repository){
				Query();
			}
			
			console.log(repository);
			var pager = $('#dg').datagrid().datagrid('getPager');	// get the pager of datagrid
			pager.pagination({
				pageSize: 10, //每页显示的记录条数，默认为10 
                pageList: [10, 20, 30], //可以设置每页记录条数的列表 
                onSelectPage: function (pageNumber, pageSize) {
                	var url = "${ctx}/erp/warehouse/repositoryPage?page="+pageNumber+"&pageSize="+pageSize+"&repository="+repository;
                    $('#dg').datagrid('options').url = url;
                    $('#dg').datagrid('reload'); //重新加载表格
                },
				buttons:[{
					iconCls:'icon-remove',
					handler:function(){
						//删除，修改状态
						$.messager.confirm('删除', '确定删除?', function(r){
							if (r){
								$.ajax({
								    url: '${ctx}/erp/warehouse/repositoryDel',         
								    data: {repId:repository},
								    dataType: "json",
								    type: "POST",          
								    success: function (data) {
								    	$.messager.alert('提示','删除完成','info',function(){
								    		window.parent.location.reload();
								    		/* window.location.href="${ctx}/erp/warehouse/toRightRepository?repository="+repository; */
								    	});
								    }
								});
								
								/* window.location.href="${ctx}/erp/warehouse/repositoryDel?repId="+repository;  */
							}
						});
					}
				},{
					iconCls:'icon-add',//新增
					handler:function(s){
						$("#dlg").dialog({
							title:"新增",
							buttons:[{
								text:'确定',
								iconCls:'icon-ok',
								handler:function(){
									var text = $('#repository').textbox('getValue');
									$.ajax({
									    url: '${ctx}/erp/warehouse/repositoryAdd',         
									    data: {'rep_Name':text,'parentId':repository},
									    dataType: "json",
									    type: "POST",          
									    success: function (data) {
									    	if(""!=data&&null!=data){
									    		$.messager.alert('提示','名字重复','info');
									    	}
									    },
									    error: function () {
									    	$.messager.alert('提示','新增完成','info',function(){
									    		window.parent.location.reload();
									    		/* window.location.href="${ctx}/erp/warehouse/toRightRepository?repository="+repository; */
									    	});
									    }
									});
								}},
								{
								text:'取消',
								handler:function(){
									$("#dlg").dialog('close');
								}}]
						});
					}
				},{
					iconCls:'icon-edit',
					handler:function(s){
						$("#dlg").dialog({
							onOpen:function(){
								$.ajax({
								    url: '${ctx}/erp/warehouse/queryRepositoryName',         
								    data: {repository:repository},
								    dataType: "json",
								    type: "POST",          
								    success: function (data) {
								    	$("#repository").textbox('setValue',data);
								    }
								});
							},
							title:"编辑",
							buttons:[{
								text:'确定',
								iconCls:'icon-ok',
								handler:function(){
									var text = $('#repository').textbox('getValue');//要修改的名字
									$.ajax({
									    url: '${ctx}/erp/warehouse/repositoryUpdate',         
									    data: {rep_Name:text,id:repository},
									    dataType: "json",
									    type: "POST",          
									    success: function (data) {
									    	if(""!=data&&null!=data){
									    		$.messager.alert('提示','名字重复','info');
									    	}
									    },
									    error: function () {
									    	$.messager.alert('提示','修改完成','info',function(){
									    		window.parent.location.reload();
									    		/* window.location.href="${ctx}/erp/warehouse/toRightRepository?repository="+repository; */
									    	});
									    	
									    }
									});
								}},
								{
								text:'取消',
								handler:function(){
									$("#dlg").dialog('close');
								}}]
						});
						
					}
				}]
			});	
			$("#dlg").dialog('close');
		})
	</script>
</body>
</html>